/**
 * 抽题策略明细列表页面js
 */
function getChapter(bookId,eleId){
	$(eleId).html('<option value="-1">全部</option>');
	if(bookId == -1){
		return;
	}
	$.post("chapter/searchByBookId",{"book.bookId":bookId},function(data){
		if(typeof data == "string"){
			data = eval("("+data+")");
		}
		$.each(data,function(){
			var opt = $("<option></option>");
			opt.html(this.name);
			opt.val(this.chapterId);
			opt.appendTo(eleId);
		});
	});
}

function showDetailDialog(id,title,href){
	href=href+"?strategeId="+stratege_id+"&gradeId="+grade_id+"&gradeName="+grade_name;
	showStrategeDetailDialog(id,title,href);
}

var $dialog ; //弹出来的对话框
function showStrategeDetailDialog(id,title,href) {
	
	$dialog = $(id);
	$dialog.find(".modal-header h4.modal-title").html(title);
	var url = href + (href.indexOf("?") == -1 ? "?" : "&") +"_=" + new Date().getTime();
	$(id + " div.modal-body").load(url, function() {
		$dialog.modal();
		var $form = $(id+" form");
		$form.bind("submit", function() {
			submitForm();
			return false;
		});
	});
}

function strategeDetailbatchDelete(url,idField){
	if(!idField){
		idField = "id";
	}
	var rows =$strategeDetialTable.bootstrapTable('getSelections');
	if(rows.length == 0){
		return;
	}
	swal({
		title : "确定要删除选中的数据吗?",
		text : "一旦删除数据将不能再恢复!",
		type : "warning",
		showCancelButton : true,
		cancelButtonText : "取消",
		confirmButtonText : "确定"
	}, function() {
		var postData = {};
		$.each(rows,function(i){
			postData["ids["+i+"]"] = this[idField];
		});
		$.post(url,postData,function(){
			$strategeDetialTable.bootstrapTable("refresh");
		});
	});
}

function submitForm() {
	var $form = $("form",$dialog);
	var postData = $form.serialize();
	var action = $form.attr("action");
	$.post(action, postData, function(data) {
		$dialog.modal("hide");
		$strategeDetialTable.bootstrapTable("refresh");
	});

}

function resetCondition(){
	$("div.conditionForm :text").val("");
	$("select").each(function(){
		this.selectedIndex = 0;
		$(this).trigger("change");
	})
}
